package com.wolfman.uploadfile.mapper;

import com.wolfman.uploadfile.po.FileUpload;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Title
 * @Description
 * @Author WolfMan
 * @Date 2021/8/23 13:53
 * @Email 2370032534@qq.com
 */
@Mapper
public interface FileUploadMapper {
    /**
     * 插入新的文件上传信息
     *
     * @param fileUpload
     */
    @Options(useGeneratedKeys = true, keyColumn = "id")
    @Insert("insert into tab_upload_file(filename,filePath,uploadProgress) values(#{filename},#{filePath},#{uploadProgress})")
    void insertOne(FileUpload fileUpload);

    /**
     * 更新进度
     *
     * @param fileUpload
     */
    @Update("update tab_upload_file set uploadProgress=#{uploadProgress} where id = #{id}")
    void updateProcess(FileUpload fileUpload);

    /**
     * 查询文件信息
     *
     * @param fileUpload
     * @return
     */
    @Select("select * from tab_upload_file where id = #{id}")
    FileUpload selectById(FileUpload fileUpload);

    /**
     * 根据id查找进度
     * @param fileUpload
     * @return
     */
    @Select("select uploadProgress from tab_upload_file where id = #{id}")
    Double selectProcessById(FileUpload fileUpload);

    /**
     * 查找所有未完成的列表
     * @return
     */
    @Select("select * from tab_upload_file where uploadProgress<100")
    List<FileUpload> selectAllUnfinished();

    /**
     * 根据id删除记录
     * @param f
     */
    @Delete("delete from tab_upload_file where id = #{id}")
    void deleteById(FileUpload f);
}
